#include "connexion.h"
#include "icore.h"
#include "alarmedialog.h"
#include <QtGui>
#include <QApplication>
#include <QtCore>


extern QString g_nomentre;
extern QString g_guidentre;
QString g_pathabsolu;
QString g_paramarg;
using namespace Common;
void myMessageOutput(QtMsgType type, const char *msg)
 {
     QFile file(qApp->applicationDirPath ()+"/errorLog.txt");
     file.open(QIODevice::ReadWrite|QIODevice::Append);
     QTextStream s(&file);
     switch (type) {
     case QtDebugMsg:
         s << "Debug: " << QString(msg) << "\n";
         break;
     case QtWarningMsg:
         s << "Warning: " << QString(msg) << "\n";
         break;
     case QtCriticalMsg:
         s << "Critical: " << QString(msg) << "\n";
         break;
     case QtFatalMsg:
         s << "Fatal: " << QString(msg) << "\n";
         abort();
     }

     file.close();
 }
 
int main(int argc, char *argv[]){
  QString donneenom;//faut-il les garder ?
  QString donneeprenom;
  qInstallMsgHandler(myMessageOutput);
  QApplication app(argc,argv);
  QFile f(app.applicationDirPath ()+"/errorLog.txt");
  f.remove();
  QStringList arguments = app.arguments();
  QFileInfo pathinfo(arguments[0]);
  g_pathabsolu = pathinfo.absolutePath();
  if(!ICore::instance()->initialize()){
     QMessageBox msgdb;
	msgdb.setWindowTitle(QObject::trUtf8("Erreur ouverture de base"));
	msgdb.setText(QObject::trUtf8("Impossible de se connecter à la base "));
	msgdb.setIcon(QMessageBox::Critical);
	msgdb.exec();
	if(QMessageBox::Ok){
	   return false;
	}
      }
  if(arguments.count() > 1){
      g_guidentre = arguments[4];
      g_paramarg = arguments[13];//correspond au nom de l'utilisateur de medintux
      qDebug() << __FILE__ << QString::number(__LINE__) << "guid = " << g_guidentre
                                                        << "g_paramarg = "<< g_paramarg;

      }
  else{
      g_nomentre="mafanfancherie";
      qDebug() << __FILE__ << QString::number(__LINE__)  ;
      }
  Alarmedialog *dialog = new Alarmedialog;
  dialog->show();
  return app.exec();
}
